<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html> 
<head>
<title>Reflection Invoke Sample</title>
<link rel="stylesheet" type="text/css" href="../../../../docs/rotor.css">
</head>

<body>		


<h1> Reflection Invoke Sample</h1>


<h2>Sample Overview</h2>


<p>This sample illustrates how to invoke different kinds of methods through 
reflection. Because the names of the methods being invoked are stored in 
strings, this mechanism provides the capability to specify methods to be invoked 
at runtime, rather than at design-time, providing the scope to give your users 
control over which particular method gets called. Although this sample focuses 
on invoking methods, you can also set and get properties and fields, if 
required.</p>


<p>In many coding scenarios, you know the task that you want to carry out before 
you want to do it. Therefore, you can specify the methods that you need to 
invoke, and the parameters you need to pass them. However, there are also 
situations where you might want to dynamically invoke methods, based upon 
specific scenarios, or user actions. This capability is available through the <b>
Reflection</b> namespace, by using the <b>InvokeMember</b> method on the <b>Type</b> 
object. </p>
<p>See the sample source code for more detailed comments.</p>


<h2>Sample Source and Build Output Locations</h2>


<p>The sample source is found in sscli20\samples\howto\reflection\invoke.&nbsp; </p>


<p>The source file is:</p>


<ul class="none">
  <li><a href="reflectioninvoke.cs">reflectioninvoke.cs</a></li>
</ul>


<p>The build output location is %_NTTREE%\samples\howto\reflection\invoke.&nbsp; 
The output file is an executable assembly named reflectioninvoke.exe.</p>


<h2>Building the Sample</h2>


<p>All samples are built from the buildall script.&nbsp;  </p>


<p>You can also build all the 
samples by switching to the root of the sample directory, sscli20\samples, and typing 
<code>build -c</code>.</p>


<p>You can build this specific sample  by switching to the sample directory and typing 
<code>build -c</code>.</p>


<h2>Running the Sample</h2>


<p>These steps require that the Shared Source CLI (SSCLI) be already built and 
functional.</p>


<ol>
  <li>Run  env.bat. </li>
  <li>Switch to the %_NTTREE%\samples\howto\reflection\invoke directory.</li>
  <li>Type the following command:<blockquote>


<p>clix reflectioninvoke.exe</p>


  </blockquote>


  </li>
</ol>


<hr>


<p><i>Copyright (c) 2006 Microsoft Corporation. All rights reserved.</i></p>
</body> 
</html>